/**
 * Predefined variables
 * Name = broadcastWidget
 * DateTime = Mon Jan 17 2022 21:50:02 GMT+0800 (中国标准时间)
 * Author = Created by zhj9922
 * FileBasename = broadcastWidget.ts
 * gitee： https://gitee.com/coyeking
 */
 
import { _decorator, Component, Node,Label,UITransform ,tween,Vec3} from 'cc';
const { ccclass, property } = _decorator;
import { userGlobal } from '../../../global/userGlobal';
 
@ccclass('broadcastWidget')
export class broadcastWidget extends Component {
    @property({
        type: Label,
        displayName:'文本',
    })
    public ui_label: Label = null;
    
    @property(Node)
    public ui_mask: Node = null;
    _width:number = 0;
	
	
    onLoad () {
        let self = this;
        let content = userGlobal.instance.getSystemInfo().notice;//后台消息
        this.ui_label.string = content;
        
        const uiTransform = this.ui_label.node.getComponent(UITransform);
        const askuiTransform = this.ui_mask.getComponent(UITransform);
        
        setTimeout(() => {
            self._width = uiTransform.width;
            if (askuiTransform.width < self._width){
                self.onAction()
            }
        }, 500);
    };
    
    onAction(){
        let self = this;
        let pos = new Vec3(0, 0, 0);
        this.ui_label.node.setPosition(pos);

        tween(self.ui_label.node)
        .to(10, { position: new Vec3(-self._width, 0, 0)} , { easing: 'smooth' })
        .call(()=>{
            self.onAction();
        })
        .start();
    }
	
}

